/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Principal.java
 *
 * Created on 08/03/2011, 09:06:07
 */

package sisgraf.view;
import java.text.SimpleDateFormat;
import java.util.Date;
import sisgraf.controler.PedidoControler;
import sisgraf.controler.PedidoTabela;
import sisgraf.dao.PedidoDaoImp;
import sisgraf.model.Faturamento;
import sisgraf.model.Pedido;

/**
 *
 * @author jordan C. Guerra
 */
public class PesquisaPedidos extends javax.swing.JDialog {
    private PedidoControler modeloControler =new PedidoControler();
    private PedidoTabela modelo;
    private Pedido pedSel;
    private String condicao;
    
    /** Creates new form Principal */
    public PesquisaPedidos(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        formComponentResized(null);
        setLocationRelativeTo(null);
        jBtAlterar.setVisible(Menu.estadoPerfil.getPermissao("ped", "A"));
        jBtConsultar.setVisible(Menu.estadoPerfil.getPermissao("ped", "C"));
        jBtConcluir.setVisible(Menu.estadoPerfil.getPermissao("ped", "CC"));
        jBtFaturar.setVisible(Menu.estadoPerfil.getPermissao("ped", "FA"));
        jBtCancelar.setVisible(Menu.estadoPerfil.getPermissao("ped", "CA"));
        jTbVisualizacao.setModel(modeloControler.getListarPedido(null));
        modeloControler.ajustarTabela(jTbVisualizacao);
        jBtAlterar.setEnabled(false);
        jBtConsultar.setEnabled(false);
        jBtConcluir.setEnabled(false);
        jBtFaturar.setEnabled(false);
        jBtCancelar.setEnabled(false);
    }
    public void setOpcao(int opcao){
        if (opcao == 1){
            jBtSelecionar.setVisible(false);
            jBtFinalizar.setVisible(true);
        } else {
            jBtSelecionar.setVisible(true);
            jBtFinalizar.setVisible(false);
        }
        this.setVisible(true);
    }
    public void setPedido(Pedido pedido){
        pedSel=pedido;
    }
    public Pedido getPedido(){
        return pedSel;
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btnGrpTipoPeriodo = new javax.swing.ButtonGroup();
        jPnlSuperior = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jPnlCentral = new javax.swing.JPanel();
        jPnlConteudo = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jTxFdNomCli = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jTxFdNomVen = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jRdBtEntregues = new javax.swing.JRadioButton();
        jRdBtPrevisaoEntrega = new javax.swing.JRadioButton();
        jCkBxFaturados = new javax.swing.JCheckBox();
        jBtPesquisar = new javax.swing.JButton();
        jBtFinalizar = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTbVisualizacao = new javax.swing.JTable();
        jTxFdNumPed = new javax.swing.JFormattedTextField();
        jTxFdDatIni = new javax.swing.JFormattedTextField();
        jTxFdDatFim = new javax.swing.JFormattedTextField();
        jBtLimpaCampos = new javax.swing.JButton();
        jPnlControle = new javax.swing.JPanel();
        jBtAlterar = new javax.swing.JButton();
        jBtConsultar = new javax.swing.JButton();
        jBtConcluir = new javax.swing.JButton();
        jBtFaturar = new javax.swing.JButton();
        jBtCancelar = new javax.swing.JButton();
        jBtSelecionar = new javax.swing.JButton();
        jPnlInferior = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentResized(java.awt.event.ComponentEvent evt) {
                formComponentResized(evt);
            }
        });

        jPnlSuperior.setBorder(new javax.swing.border.MatteBorder(null));

        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("SISTEMA DE ORÇAMENTOS PARA SERVIÇOS GRAFICOS");
        jLabel1.setMinimumSize(new java.awt.Dimension(0, 14));

        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel2.setText("Pesquisa de Pedidos");
        jLabel2.setMinimumSize(new java.awt.Dimension(0, 14));

        javax.swing.GroupLayout jPnlSuperiorLayout = new javax.swing.GroupLayout(jPnlSuperior);
        jPnlSuperior.setLayout(jPnlSuperiorLayout);
        jPnlSuperiorLayout.setHorizontalGroup(
            jPnlSuperiorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 651, Short.MAX_VALUE)
            .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 651, Short.MAX_VALUE)
        );
        jPnlSuperiorLayout.setVerticalGroup(
            jPnlSuperiorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPnlSuperiorLayout.createSequentialGroup()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jPnlCentral.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPnlCentral.setMinimumSize(new java.awt.Dimension(100, 0));

        jPnlConteudo.setBorder(javax.swing.BorderFactory.createLineBorder(null));

        jLabel5.setText("Número:");

        jLabel6.setText("Cliente:");

        jLabel7.setText("Vendedor:");

        jLabel8.setText("Período de");

        jLabel9.setText("à");

        btnGrpTipoPeriodo.add(jRdBtEntregues);
        jRdBtEntregues.setText("Entregues");

        btnGrpTipoPeriodo.add(jRdBtPrevisaoEntrega);
        jRdBtPrevisaoEntrega.setText("Previsão de Entrega");

        jCkBxFaturados.setText("Faturados");

        jBtPesquisar.setText("Pesquisar");
        jBtPesquisar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtPesquisarActionPerformed(evt);
            }
        });

        jBtFinalizar.setText("Finalizar");
        jBtFinalizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtFinalizarActionPerformed(evt);
            }
        });

        jTbVisualizacao.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jTbVisualizacao.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(jTbVisualizacao);

        try {
            jTxFdDatIni.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        try {
            jTxFdDatFim.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.MaskFormatter("##/##/####")));
        } catch (java.text.ParseException ex) {
            ex.printStackTrace();
        }

        jBtLimpaCampos.setText("Limpar Campos de Pesqusa");
        jBtLimpaCampos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtLimpaCamposActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPnlConteudoLayout = new javax.swing.GroupLayout(jPnlConteudo);
        jPnlConteudo.setLayout(jPnlConteudoLayout);
        jPnlConteudoLayout.setHorizontalGroup(
            jPnlConteudoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPnlConteudoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPnlConteudoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPnlConteudoLayout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTxFdNumPed, javax.swing.GroupLayout.PREFERRED_SIZE, 49, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel6)
                        .addGap(18, 18, 18)
                        .addComponent(jTxFdNomCli, javax.swing.GroupLayout.DEFAULT_SIZE, 463, Short.MAX_VALUE))
                    .addGroup(jPnlConteudoLayout.createSequentialGroup()
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTxFdNomVen, javax.swing.GroupLayout.DEFAULT_SIZE, 562, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPnlConteudoLayout.createSequentialGroup()
                        .addComponent(jLabel8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTxFdDatIni, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 6, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(12, 12, 12)
                        .addComponent(jTxFdDatFim, javax.swing.GroupLayout.DEFAULT_SIZE, 81, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addGroup(jPnlConteudoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPnlConteudoLayout.createSequentialGroup()
                                .addComponent(jRdBtEntregues)
                                .addGap(30, 30, 30)
                                .addComponent(jCkBxFaturados))
                            .addComponent(jRdBtPrevisaoEntrega))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPnlConteudoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPnlConteudoLayout.createSequentialGroup()
                                .addComponent(jBtPesquisar)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jBtFinalizar))
                            .addComponent(jBtLimpaCampos, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addGap(21, 21, 21))
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 647, Short.MAX_VALUE)
        );
        jPnlConteudoLayout.setVerticalGroup(
            jPnlConteudoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPnlConteudoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPnlConteudoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPnlConteudoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel6)
                        .addComponent(jLabel5)
                        .addComponent(jTxFdNumPed, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jTxFdNomCli, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPnlConteudoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jTxFdNomVen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPnlConteudoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPnlConteudoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel8)
                        .addComponent(jCkBxFaturados)
                        .addComponent(jBtPesquisar)
                        .addComponent(jBtFinalizar)
                        .addComponent(jTxFdDatIni, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jTxFdDatFim, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel9))
                    .addComponent(jRdBtEntregues, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPnlConteudoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPnlConteudoLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 9, Short.MAX_VALUE)
                        .addComponent(jRdBtPrevisaoEntrega, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18))
                    .addGroup(jPnlConteudoLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jBtLimpaCampos)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 192, Short.MAX_VALUE))
        );

        jPnlControle.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jBtAlterar.setText("Alterar");
        jBtAlterar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtAlterarActionPerformed(evt);
            }
        });

        jBtConsultar.setText("Consultar");
        jBtConsultar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtConsultarActionPerformed(evt);
            }
        });

        jBtConcluir.setText("Concluir");
        jBtConcluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtConcluirActionPerformed(evt);
            }
        });

        jBtFaturar.setText("Faturar");
        jBtFaturar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtFaturarActionPerformed(evt);
            }
        });

        jBtCancelar.setText("Cancelar");
        jBtCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtCancelarActionPerformed(evt);
            }
        });

        jBtSelecionar.setText("Selecionar");
        jBtSelecionar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtSelecionarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPnlControleLayout = new javax.swing.GroupLayout(jPnlControle);
        jPnlControle.setLayout(jPnlControleLayout);
        jPnlControleLayout.setHorizontalGroup(
            jPnlControleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPnlControleLayout.createSequentialGroup()
                .addContainerGap(167, Short.MAX_VALUE)
                .addComponent(jBtSelecionar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jBtAlterar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jBtConsultar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jBtConcluir)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jBtFaturar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jBtCancelar)
                .addContainerGap())
        );
        jPnlControleLayout.setVerticalGroup(
            jPnlControleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPnlControleLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPnlControleLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBtCancelar)
                    .addComponent(jBtFaturar)
                    .addComponent(jBtConcluir)
                    .addComponent(jBtConsultar)
                    .addComponent(jBtAlterar)
                    .addComponent(jBtSelecionar))
                .addContainerGap())
        );

        javax.swing.GroupLayout jPnlCentralLayout = new javax.swing.GroupLayout(jPnlCentral);
        jPnlCentral.setLayout(jPnlCentralLayout);
        jPnlCentralLayout.setHorizontalGroup(
            jPnlCentralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPnlControle, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPnlConteudo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPnlCentralLayout.setVerticalGroup(
            jPnlCentralLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPnlCentralLayout.createSequentialGroup()
                .addComponent(jPnlConteudo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPnlControle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jPnlInferior.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel3.setText("Gráfica Modêlo");

        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel4.setText("Grupo de Estudo PMA Anhanguera");

        javax.swing.GroupLayout jPnlInferiorLayout = new javax.swing.GroupLayout(jPnlInferior);
        jPnlInferior.setLayout(jPnlInferiorLayout);
        jPnlInferiorLayout.setHorizontalGroup(
            jPnlInferiorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPnlInferiorLayout.createSequentialGroup()
                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 333, Short.MAX_VALUE)
                .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 206, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jPnlInferiorLayout.setVerticalGroup(
            jPnlInferiorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPnlInferiorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel3))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPnlCentral, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPnlInferior, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPnlSuperior, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPnlSuperior, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPnlCentral, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPnlInferior, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    
    private void formComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentResized
        // TODO add your handling code here:
        int dif = this.getHeight()-jPnlSuperior.getHeight()-jPnlCentral.getHeight()-jPnlInferior.getHeight()-6;
        jPnlCentral.setSize(this.getWidth(),this.getHeight()-jPnlSuperior.getHeight()-jPnlInferior.getHeight()-dif);
        jPnlConteudo.setSize(jPnlCentral.getWidth(),jPnlCentral.getHeight()-jPnlControle.getHeight());
        jPnlControle.setSize(jPnlCentral.getWidth(), jPnlControle.getHeight());
        jPnlControle.setLocation(0, jPnlConteudo.getHeight());
    }//GEN-LAST:event_formComponentResized

    private void jBtFinalizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtFinalizarActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_jBtFinalizarActionPerformed

    private void jBtPesquisarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtPesquisarActionPerformed
        // TODO add your handling code here:
        condicao = "";
        String conector = "";
        String dataIni = "";
        String dataFim = "";
        String dataPes = "";
        String erroMensagem = ""; // jTxFdNumPed
        String paNumPed=jTxFdNumPed.getText().replaceAll("\\.", "");
        if (!paNumPed.equals("")){
            if (Integer.parseInt(paNumPed) != 0){
                condicao="p.id = "+paNumPed;
                conector = " and ";
            }
        }
        if (!jTxFdNomCli.getText().equals("")){
            condicao = condicao + conector + "p.itemOrcamento.orcamento.cliente.nom_cli like '"+jTxFdNomCli.getText()+"%'";
            conector = " and ";
        }
        if (!jTxFdNomVen.getText().equals("")){
            condicao = condicao + conector + "p.itemOrcamento.orcamento.vendedor.nom_ven like '"+jTxFdNomVen.getText()+"%'";
            conector = " and ";
        }
        if ((btnGrpTipoPeriodo.getSelection()==jRdBtPrevisaoEntrega.getModel())||
            (btnGrpTipoPeriodo.getSelection()==jRdBtEntregues.getModel())){
            if (!jTxFdDatIni.getText().equals("")){
                if (!Menu.validaData(jTxFdDatIni.getText())){
                    erroMensagem="Data inicial invalida\n";
                } else {
                    dataIni=jTxFdDatIni.getText();
                }
            }
            if (!jTxFdDatFim.getText().equals("")){
                if (!Menu.validaData(jTxFdDatFim.getText())){
                    erroMensagem="Data final invalida\n";
                } else {
                    dataFim=jTxFdDatFim.getText();
                }
            }
            if (btnGrpTipoPeriodo.getSelection()==jRdBtPrevisaoEntrega.getModel()){
                dataPes="p.dataPrevisaoEntrega";
            } else {
                dataPes="p.dataEntrega";
            }
            condicao = condicao + conector +dataPes+ " >= '" +Menu.convData(dataIni, 0) + "' and "+dataPes+" <= '" +Menu.convData(dataFim, 0)+"'";
            conector = " and ";
        }
        if (jCkBxFaturados.isSelected()){
            condicao = condicao + conector + " p.dataFaturamento is not null ";
            conector = " and ";
        }
        if (!erroMensagem.equals("")){
           javax.swing.JOptionPane.showMessageDialog(null, erroMensagem , "Dados Informados Invalidos", javax.swing.JOptionPane.INFORMATION_MESSAGE);
        } else {
            jTbVisualizacao.setModel(modeloControler.getListarPedido(condicao));
            modeloControler.ajustarTabela(jTbVisualizacao);
            if (jTbVisualizacao.getRowCount()>0){
                jBtAlterar.setEnabled(true);
                jBtConsultar.setEnabled(true);
                jBtConcluir.setEnabled(true);
                jBtFaturar.setEnabled(true);
                jBtCancelar.setEnabled(true);
            } else{
                jBtAlterar.setEnabled(false);
                jBtConsultar.setEnabled(false);
                jBtConcluir.setEnabled(false);
                jBtFaturar.setEnabled(false);
                jBtCancelar.setEnabled(false);
            }
        }
    }//GEN-LAST:event_jBtPesquisarActionPerformed

    private void jBtAlterarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtAlterarActionPerformed
        // TODO add your handling code here:
        sisgraf.model.Pedido ped;
        if (jTbVisualizacao.getSelectedRow()>=0)
        {
            int linha = jTbVisualizacao.getSelectedRow();
            modelo = (PedidoTabela) jTbVisualizacao.getModel();
            int id = modelo.getPedido(linha).getId();
            ped=modeloControler.prepararAlterarPedido(id);
            if (ped==null){
                javax.swing.JOptionPane.showMessageDialog(null, "Erro ao preparar Pedido para alteração" , "Acesso ao Banco de Dados", javax.swing.JOptionPane.INFORMATION_MESSAGE);
            } else {
                modelo.setPedido(linha, ped);
                Pedidos pedidos = new Pedidos(new javax.swing.JFrame(), true);
                pedidos.setPedido(modelo.getPedido(linha));
                pedidos.setControler(modeloControler);
                pedidos.setOpcao(Menu.OP_PESQ_ALT);
                jTbVisualizacao.setModel(modeloControler.getListarPedido(condicao));
                modeloControler.ajustarTabela(jTbVisualizacao);
            }
        } else
        {
            javax.swing.JOptionPane.showMessageDialog(null, "É necessário Selecionar um Pedido para Alteração", "Informação de Alteração", javax.swing.JOptionPane.INFORMATION_MESSAGE);
        }
    }//GEN-LAST:event_jBtAlterarActionPerformed

    private void jBtConsultarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtConsultarActionPerformed
        // TODO add your handling code here:
        PedidoDaoImp pedidoDaoImp = new PedidoDaoImp();
        sisgraf.model.Pedido ped;
        if (jTbVisualizacao.getSelectedRow()>=0)
        {
            int linha = jTbVisualizacao.getSelectedRow();
            modelo = (PedidoTabela) jTbVisualizacao.getModel();
            int id = modelo.getPedido(linha).getId();
            ped=pedidoDaoImp.getPedido(id);
            if (ped==null){
                javax.swing.JOptionPane.showMessageDialog(null, "Erro ao preparar Pedido para consulta" , "Acesso ao Banco de Dados", javax.swing.JOptionPane.INFORMATION_MESSAGE);
            } else {
                modelo.setPedido(linha, ped);
                Pedidos pedidos = new Pedidos(new javax.swing.JFrame(), true);
                pedidos.setPedido(modelo.getPedido(linha));
                pedidos.setControler(modeloControler);
                pedidos.setOpcao(Menu.OP_PESQ_CON);
            }
        } else
        {
            javax.swing.JOptionPane.showMessageDialog(null, "É necessário Selecionar um Pedido para Consulta", "Informação de Alteração", javax.swing.JOptionPane.INFORMATION_MESSAGE);
        }
    }//GEN-LAST:event_jBtConsultarActionPerformed

    private void jBtConcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtConcluirActionPerformed
        // TODO add your handling code here:
        sisgraf.model.Pedido ped;
        if (jTbVisualizacao.getSelectedRow()>=0)
        {
            int linha = jTbVisualizacao.getSelectedRow();
            modelo = (PedidoTabela) jTbVisualizacao.getModel();
            if (modelo.getPedido(linha).getDataEntrega()==null){
                int id = modelo.getPedido(linha).getId();
                ped=modeloControler.prepararAlterarPedido(id);
                if (ped==null){
                    javax.swing.JOptionPane.showMessageDialog(null, "Erro ao preparar Pedido para concluir" , "Acesso ao Banco de Dados", javax.swing.JOptionPane.INFORMATION_MESSAGE);
                } else {
                    Date d = new Date();
                    String date;
                    SimpleDateFormat formato = new SimpleDateFormat("dd/MM/yyyy");
                    date=formato.format(d);
                    ped.setDataEntrega(date);
                    if (!modeloControler.alterarPedido(ped)){
                        javax.swing.JOptionPane.showMessageDialog(null,
                                "Erro na atualização dos dados do pedido",
                                "Acesso ao Banco de Dados",
                                javax.swing.JOptionPane.INFORMATION_MESSAGE);
                    }
                    jTbVisualizacao.setModel(modeloControler.getListarPedido(condicao));
                    modeloControler.ajustarTabela(jTbVisualizacao);
                }
            } else {
                javax.swing.JOptionPane.showMessageDialog(null, "Serviço já entregue não pode ser concluído\n"
                        + "Data de entrega:"+modelo.getPedido(linha).getDataEntregaForm(),
                        "Informação de Alteração", javax.swing.JOptionPane.INFORMATION_MESSAGE);
            }

        } else
        {
            javax.swing.JOptionPane.showMessageDialog(null, "É necessário Selecionar um Pedido para Concluir", "Informação de Alteração", javax.swing.JOptionPane.INFORMATION_MESSAGE);
        }

    }//GEN-LAST:event_jBtConcluirActionPerformed

    private void jBtFaturarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtFaturarActionPerformed
        // TODO add your handling code here:
        sisgraf.model.Pedido ped;
        if (jTbVisualizacao.getSelectedRow()>=0)
        {
            int linha = jTbVisualizacao.getSelectedRow();
            modelo = (PedidoTabela) jTbVisualizacao.getModel();
            if (modelo.getPedido(linha).getDataFaturamento()==null){
                int id = modelo.getPedido(linha).getId();
                ped=modeloControler.prepararAlterarPedido(id);
                if (ped==null){
                    javax.swing.JOptionPane.showMessageDialog(null, "Erro ao preparar Pedido para faturar" , "Acesso ao Banco de Dados", javax.swing.JOptionPane.INFORMATION_MESSAGE);
                } else {
                    Date d = new Date();
                    String date;
                    SimpleDateFormat formato = new SimpleDateFormat("dd/MM/yyyy");
                    date=formato.format(d);
                    ped.setDataFaturamento(date);
                    if (!modeloControler.alterarPedido(ped)){
                        javax.swing.JOptionPane.showMessageDialog(null,
                                "Erro na atualização dos dados do pedido",
                                "Acesso ao Banco de Dados",
                                javax.swing.JOptionPane.INFORMATION_MESSAGE);
                    } else {
                        Faturamento faturamento = new Faturamento();
                        faturamento.setCpf(ped.getItemOrcamento().getOrcamento().getCliente().getCpf_cnpj());
                        faturamento.setNome(ped.getItemOrcamento().getOrcamento().getCliente().getNom_cli());
                        faturamento.setRua(ped.getItemOrcamento().getOrcamento().getCliente().getEnd_log());
                        faturamento.setNumero(ped.getItemOrcamento().getOrcamento().getCliente().getEnd_num().toString());
                        faturamento.setComplemento(ped.getItemOrcamento().getOrcamento().getCliente().getEnd_com());
                        faturamento.setBairro(ped.getItemOrcamento().getOrcamento().getCliente().getEnd_bai());
                        faturamento.setCep(ped.getItemOrcamento().getOrcamento().getCliente().getEnd_cep().toString());
                        faturamento.setCidade(ped.getItemOrcamento().getOrcamento().getCliente().getEnd_cid());
                        faturamento.setUf(ped.getItemOrcamento().getOrcamento().getCliente().getEnd_uf());
                        faturamento.setEmail(ped.getItemOrcamento().getOrcamento().getCliente().getEmail());
                        faturamento.setTelFixo(ped.getItemOrcamento().getOrcamento().getCliente().getTel_fix());
                        faturamento.setTelCel(ped.getItemOrcamento().getOrcamento().getCliente().getTel_cel());
                        faturamento.setFax(ped.getItemOrcamento().getOrcamento().getCliente().getTel_fax());
                        faturamento.setAniverssario(ped.getItemOrcamento().getOrcamento().getCliente().getAniversario());

                        faturamento.setDataFatura(ped.getDataFaturamentoForm());
                        faturamento.setValorEntrada(ped.getValor().toString());
                        faturamento.setNumParcelas("1");
                        faturamento.setValorParcela("0.00");
                        String dtVencimento = Menu.addData(ped.getDataFaturamentoForm(),20);
                        faturamento.setDataVencimento(dtVencimento);
                        faturamento.setDias("0");
                        faturamento.gravar();
                    }
                    jTbVisualizacao.setModel(modeloControler.getListarPedido(condicao));
                    modeloControler.ajustarTabela(jTbVisualizacao);
                }
            } else {
                javax.swing.JOptionPane.showMessageDialog(null, "Serviço já faturado não pode ser faturado\n"
                        + "Data de faturamento:"+modelo.getPedido(linha).getDataFaturamentoForm(),
                        "Informação de Alteração", javax.swing.JOptionPane.INFORMATION_MESSAGE);
            }

        } else
        {
            javax.swing.JOptionPane.showMessageDialog(null, "É necessário Selecionar um Pedido para Faturar", "Informação de Alteração", javax.swing.JOptionPane.INFORMATION_MESSAGE);
        }
    }//GEN-LAST:event_jBtFaturarActionPerformed

    private void jBtCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtCancelarActionPerformed
        // TODO add your handling code here:
        sisgraf.model.Pedido ped;
        if (jTbVisualizacao.getSelectedRow()>=0)
        {
            int linha = jTbVisualizacao.getSelectedRow();
            modelo = (PedidoTabela) jTbVisualizacao.getModel();
            if (modelo.getPedido(linha).getDataCancelamento()==null){
                int id = modelo.getPedido(linha).getId();
                ped=modeloControler.prepararAlterarPedido(id);
                if (ped==null){
                    javax.swing.JOptionPane.showMessageDialog(null, "Erro ao preparar Pedido para cancelar" , "Acesso ao Banco de Dados", javax.swing.JOptionPane.INFORMATION_MESSAGE);
                } else {
                    String motivo=javax.swing.JOptionPane.showInputDialog(null, "Informe o motivo do cancelamento", null);
                    if (motivo!=null){
                        Date d = new Date();
                        String date;
                        SimpleDateFormat formato = new SimpleDateFormat("dd/MM/yyyy");
                        date=formato.format(d);
                        ped.setDataCancelamento(date);
                        String obs=ped.getObservacoes();
                        obs=obs+"\n"+motivo;
                        ped.setObservacoes(obs);
                        if (!modeloControler.alterarPedido(ped)){
                            javax.swing.JOptionPane.showMessageDialog(null,
                                    "Erro na atualização dos dados do pedido",
                                    "Acesso ao Banco de Dados",
                                    javax.swing.JOptionPane.INFORMATION_MESSAGE);
                        }
                        jTbVisualizacao.setModel(modeloControler.getListarPedido(condicao));
                        modeloControler.ajustarTabela(jTbVisualizacao);
                    }
                }
            } else {
                javax.swing.JOptionPane.showMessageDialog(null, "Serviço já cancelado não pode ser cancelado\n"
                        + "Data de cancelamento:"+modelo.getPedido(linha).getDataCancelamentoForm(),
                        "Informação de Alteração", javax.swing.JOptionPane.INFORMATION_MESSAGE);
            }

        } else
        {
            javax.swing.JOptionPane.showMessageDialog(null, "É necessário Selecionar um Pedido para Faturar", "Informação de Alteração", javax.swing.JOptionPane.INFORMATION_MESSAGE);
        }

    }//GEN-LAST:event_jBtCancelarActionPerformed

    private void jBtSelecionarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtSelecionarActionPerformed
        // TODO add your handling code here:
        if (jTbVisualizacao.getSelectedRow()>=0)
        {
            int linha = jTbVisualizacao.getSelectedRow();
            modelo = (PedidoTabela) jTbVisualizacao.getModel();
            pedSel = (Pedido) modelo.getPedido(linha);
        } else
        {
            javax.swing.JOptionPane.showMessageDialog(null, "É necessário Selecionar um Pedido para Seleção", "Informação de Alteração", javax.swing.JOptionPane.INFORMATION_MESSAGE);
        }
        this.setVisible(false);

    }//GEN-LAST:event_jBtSelecionarActionPerformed

    private void jBtLimpaCamposActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBtLimpaCamposActionPerformed
        // TODO add your handling code here:
        jTxFdNumPed.setText("");
        jTxFdNomCli.setText("");
        jTxFdNomVen.setText("");
        btnGrpTipoPeriodo.clearSelection();
        jTxFdDatIni.setText("");
        jTxFdDatFim.setText("");
        jCkBxFaturados.setSelected(false);
    }//GEN-LAST:event_jBtLimpaCamposActionPerformed
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                Principal dialog = new Principal(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup btnGrpTipoPeriodo;
    private javax.swing.JButton jBtAlterar;
    private javax.swing.JButton jBtCancelar;
    private javax.swing.JButton jBtConcluir;
    private javax.swing.JButton jBtConsultar;
    private javax.swing.JButton jBtFaturar;
    private javax.swing.JButton jBtFinalizar;
    private javax.swing.JButton jBtLimpaCampos;
    private javax.swing.JButton jBtPesquisar;
    private javax.swing.JButton jBtSelecionar;
    private javax.swing.JCheckBox jCkBxFaturados;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPnlCentral;
    private javax.swing.JPanel jPnlConteudo;
    private javax.swing.JPanel jPnlControle;
    private javax.swing.JPanel jPnlInferior;
    private javax.swing.JPanel jPnlSuperior;
    private javax.swing.JRadioButton jRdBtEntregues;
    private javax.swing.JRadioButton jRdBtPrevisaoEntrega;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTbVisualizacao;
    private javax.swing.JFormattedTextField jTxFdDatFim;
    private javax.swing.JFormattedTextField jTxFdDatIni;
    private javax.swing.JTextField jTxFdNomCli;
    private javax.swing.JTextField jTxFdNomVen;
    private javax.swing.JFormattedTextField jTxFdNumPed;
    // End of variables declaration//GEN-END:variables
    
}
